package com.xonro.common.histrans.sfeg.job.update.contarct;

import com.actionsoft.bpms.commons.database.RowMap;
import com.actionsoft.bpms.schedule.IJob;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.sdk.local.SDK;
import com.xonro.common.histrans.base.consts.SfegConst;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.util.List;

public class UpdateContractRecord implements IJob {
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        String sql="SELECT * FROM BO_XR_MDM_CONTRACT ";
        List<RowMap> maps = DBSql.getMaps(sql);
        for(RowMap m:maps){
            String id=m.getString("ID");
            String contractNo = m.getString("CONTRACT_NO");
            RowMap mainMap = SDK.getCCAPI().getRDSAPI(SfegConst.CCID).getMap("SELECT * FROM tb_ContractInfo  WHERE HTBH = '" + contractNo + "'  ");
            String ctState = mainMap.getString("ctState");
           // String inureData = mainMap.getString("inureData");
            String updateSql="UPDATE BO_XR_MDM_CONTRACT set CONTRACT_STATE='"+ctState+"' WHERE ID='"+id+"'";
            DBSql.update(updateSql);
        }
         List<RowMap> aMaps = DBSql.getMaps("SELECT ID,CONTRACT_NO  FROM BO_XR_EPM_A_CONTRACT  ");
        for(RowMap m: maps){
            String id=m.getString("ID");
            String contractNo = m.getString("CONTRACT_NO");
            RowMap mainMap = SDK.getCCAPI().getRDSAPI(SfegConst.CCID).getMap("SELECT * FROM tb_ContractInfo  WHERE HTBH = '" + contractNo + "'  ");
            if(null==mainMap){
                continue;
            }
            String fillDate = mainMap.getString("fillDate");
            String ctState = mainMap.getString("ctState");
            String ctCode = mainMap.getString("ctCode");
            String updateSql="UPDATE BO_XR_EPM_A_CONTRACT set PROCESS_FLAG='"+ctState+"',APPLY_DATE='"+fillDate+"',APPLY_NO='"+ctCode+"' WHERE ID='"+id+"'";
            DBSql.update(updateSql);
        }

        List<RowMap> bMaps = DBSql.getMaps("SELECT ID,CONTRACT_NO  FROM BO_XR_SP_B_CONTRACT_SIGN  ");
        for(RowMap m: bMaps){
            String id=m.getString("ID");
            String contractNo = m.getString("CONTRACT_NO");
            RowMap mainMap = SDK.getCCAPI().getRDSAPI(SfegConst.CCID).getMap("SELECT * FROM tb_ContractInfo  WHERE HTBH = '" + contractNo + "'  ");
            if(null==mainMap){
                continue;
            }
            String fillDate = mainMap.getString("fillDate");
            String ctState = mainMap.getString("ctState");
            String ctCode = mainMap.getString("ctCode");
            String updateSql="UPDATE BO_XR_SP_B_CONTRACT_SIGN set PROCESS_FLAG='"+ctState+"',APPLY_DATE='"+fillDate+"',APPLY_NO='"+ctCode+"' WHERE ID='"+id+"'";
            DBSql.update(updateSql);
        }

        List<RowMap> signMaps = DBSql.getMaps("SELECT ID,CONTRACT_NO  FROM BO_XR_CM_CONTRACT_SIGN  ");
        for(RowMap m: signMaps){
            String id=m.getString("ID");
            String contractNo = m.getString("CONTRACT_NO");
            RowMap mainMap = SDK.getCCAPI().getRDSAPI(SfegConst.CCID).getMap("SELECT * FROM tb_ContractInfo  WHERE HTBH = '" + contractNo + "'  ");
            if(null==mainMap){
                continue;
            }
            String fillDate = mainMap.getString("fillDate");
            String ctState = mainMap.getString("ctState");
            String ctCode = mainMap.getString("ctCode");
            String updateSql="UPDATE BO_XR_CM_CONTRACT_SIGN set PROCESS_FLAG='"+ctState+"',APPLY_DATE='"+fillDate+"',APPLY_NO='"+ctCode+"' WHERE ID='"+id+"'";
            DBSql.update(updateSql);
        }


    }
}
